//
//  NeedClaimTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/8/5.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "NeedClaimTableViewCell.h"

@interface NeedClaimTableViewCell ()
//标题
@property (nonatomic , strong) UILabel * cellTitleLabel;
//需求位置
@property (nonatomic , strong) UILabel * needAddressLabel;
//认领时间
@property (nonatomic , strong) UILabel * getTimeLabel;
//剩余时间
@property (nonatomic , strong) UILabel * remainingTimeLabel;
//当前状态
@property (nonatomic , strong) UILabel * statusLabel;
@end

@implementation NeedClaimTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initMyCell];
    }
    return self;
}


-(void)initMyCell{
    TenGrayShadowView *under = [[TenGrayShadowView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 10 * [UIScreen zj_screenHScale])];
    under.backgroundColor = [UIColor themeGrayColor];
    under.isRemoveTop = YES;
    [self.contentView addSubview:under];
    //logo
    UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ItemWidth * 24, ItemHeight * 45, ItemHeight * 39, ItemHeight * 39)];
    logoImageView.image = [UIImage imageNamed:@"mine_con_xqrl"];
    [self.contentView addSubview:logoImageView];
    
    [self.contentView addSubview:self.cellTitleLabel];
    [self.contentView addSubview:self.needAddressLabel];
    [self.contentView addSubview:self.getTimeLabel];
    [self.contentView addSubview:self.remainingTimeLabel];
    [self.contentView addSubview:self.optionButton];
    [self.contentView addSubview:self.statusLabel];
    self.needAddressLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.cellTitleLabel , ItemHeight * 26).widthIs(ItemWidth * 500).heightIs(ItemHeight * 39);
    
    self.getTimeLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.needAddressLabel , 0).widthIs(ItemWidth * 500).heightIs(ItemHeight * 39);
    
    self.remainingTimeLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.getTimeLabel , 0).widthIs(ItemWidth * 500).heightIs(ItemHeight * 39);
    
    self.statusLabel.sd_layout.rightSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , ItemHeight * 90).widthIs(ItemWidth * 124).heightIs(ItemHeight * 39);
    
    self.optionButton.sd_layout.leftSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , -1).widthIs([UIScreen zj_screenWith]).heightIs(ItemHeight * 60);
}

-(void)setModel:(BranchNormalModel *)model
{
    _model = model;
    BranchRequirementModel * tempModel = (BranchRequirementModel *)model;
    self.cellTitleLabel.frame = CGRectMake(ItemWidth * 74, self.titleBeginY + 20 * ItemHeight, ItemWidth * 642, model.titleHeight);
    self.cellTitleLabel.attributedText = model.titleAttributedString;
    self.needAddressLabel.attributedText = tempModel.addressAttributedString;
    NSString * timeString = tempModel.REL_TIME;
    timeString = [timeString componentsSeparatedByString:@"."][0];
    if (timeString.length > 0) {
        timeString = [NSDateFormatter formatterDateStringWithDateString:timeString];
    }
    self.getTimeLabel.text = [NSString stringWithFormat:@"认领时间：%@" , timeString];
    if ([tempModel.DAYS integerValue] < 0) {
        self.remainingTimeLabel.text = [NSString stringWithFormat:@"剩余时间：0天"];
    }
    else{
        self.remainingTimeLabel.text = [NSString stringWithFormat:@"剩余时间：%@天" , tempModel.DAYS];
    }
    
    self.statusLabel.text = @"已认领";
    self.needAddressLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.cellTitleLabel , ItemHeight * 26).widthIs(ItemWidth * 500).heightIs(tempModel.addressHeight);
    [self.needAddressLabel updateLayout];
}





//标题
-(UILabel *)cellTitleLabel
{
    if (!_cellTitleLabel) {
        _cellTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 25, ItemWidth * 642, ItemHeight * 39) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _cellTitleLabel;
}
//需求位置
-(UILabel *)needAddressLabel
{
    if (!_needAddressLabel) {
        _needAddressLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 90, ItemWidth * 500 , ItemHeight * 39) font:14 textColor:[UIColor textBlackColor] text:@""];
    }
    return _needAddressLabel;
}
//认领时间
-(UILabel *)getTimeLabel
{
    if (!_getTimeLabel) {
        _getTimeLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 119, ItemWidth * 500, ItemHeight * 39) font:14 textColor:[UIColor textBlackColor] text:@""];
    }
    return _getTimeLabel;
}

//剩余时间
-(UILabel *)remainingTimeLabel
{
    if (!_remainingTimeLabel) {
        _remainingTimeLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 158, ItemWidth * 500, ItemHeight * 39) font:14 textColor:[UIColor textBlackColor] text:@""];
    }
    return _remainingTimeLabel;
}

//下方按钮
-(UIButton *)optionButton
{
    if (!_optionButton) {
        _optionButton = [ToolClass createButtonWithFrame:CGRectMake(0, ItemHeight * 188, [UIScreen zj_screenWith], ItemHeight * 60) text:@"确认完成" textColor:[UIColor zj_colorWithHexString:@"558b2f"] imageName:@"" font:16];
        _optionButton.backgroundColor = [UIColor zj_colorWithHexString:@"ecf9e8"];
//        _optionButton.layer.shadowOffset = CGSizeMake(0, 2);
//        _optionButton.layer.shadowColor = [UIColor blackColor].CGColor;
//        _optionButton.layer.shadowOpacity = 0.2;
    }
    return _optionButton;
}
//当前状态
-(UILabel *)statusLabel
{
    if (!_statusLabel) {
        _statusLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 626, ItemHeight * 119, ItemWidth * 124, ItemHeight * 39) font:14 textColor:[UIColor themeColor] text:@""];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _statusLabel;
}




@end
